define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'video/index/index' + location.search,
                    add_url: 'video/index/add',
                    edit_url: 'video/index/edit',
                    del_url: 'video/index/del',
                    multi_url: 'video/index/multi',
                    import_url: 'video/index/import',
                    table: 'videos',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},

                        {field: 'g_name', title: __('分组')},

                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'desc', title: __('Desc'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'news', title: __('News'), searchList: {"0":__('News 0'),"1":__('News 1')}, formatter: Table.api.formatter.normal},
                        // {field: 'files', title: __('Files'), operate: false, formatter: Table.api.formatter.files},
                        // {field: 'videos_cate_id', title: __('Videos_cate_id')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'detail',
                                    text: __(''),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'video/index/getlogs',
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    }
                                }
                            ]

                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        getlogs: function () {

            Table.api.init({
                extend: {

                }

            });

            var table2 = $("#table2");
            var id=$("#ids").val();

            table2.bootstrapTable({
                url: 'video/index/getlogs/ids/'+id,
                search: false,
                showToggle:false,
                showColumns:false,
                showExport:false,
                showSearch:false,
                searchFormVisible:false,
                columns: [
                    [
                        {field: 'id', title: 'ID'},
                        {field: 'nickname', title: __('用户')},
                        {field: 'bi', title: __('查看')},

                        {field: 'score', title: __('得分')},
                        {field: 'times', title: __('Createtime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                    ]
                ]
            });
            // 为表格2绑定事件
            Table.api.bindevent(table2);
        },



        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
